package dmir.wikipedia.addons;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * 
 * @author ivo
 *
 */
public class EnglishWikiPopulationUtil {
    
    private static final Pattern enPopPattern = Pattern.compile(
            "\\|\\s*(\\d\\d\\d\\dpop|pop\\d\\d\\d\\dcensus|population_total|pop|population_estimate|population_census|population)\\s*=\\s*([\\d,]+)", 
            Pattern.CASE_INSENSITIVE);

    public static final EnglishWikiPopulationUtil INSTANCE = new EnglishWikiPopulationUtil();

    protected EnglishWikiPopulationUtil() { this.popPattern = enPopPattern; }
    
    protected Pattern popPattern;

    public Long getPopulation(CharSequence infobox) {
        try {

            Matcher m = popPattern.matcher(infobox);
            if (m.find()) { 
            	return new Long(m.group(2).replaceAll(",", ""));
            }
        	
        } catch (Exception e) {
        	e.printStackTrace();
        }
        return null;
    }

}
